package com.woniu.sharepark.util;

import com.woniu.sharepark.leasesystem.common.dao.OrderFormDAO;
import com.woniu.sharepark.leasesystem.common.pojo.OrderForm;
import com.woniu.sharepark.leasesystem.common.service.OrderFormService;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author DELL
 * @date 2019/6/11 10:22
 * version v1.0
 */

@Component
@Configurable
@EnableScheduling
@EnableAsync
public class ScheduledUtil {

  @Resource
    private OrderFormDAO orderFormDAO;

    @Resource
    private OrderFormService orderFormService;

   @Scheduled(cron = "0/60 * * * * *")
    public void timer() throws ParseException {
        //获取当前时间
        LocalDateTime localDateTime = LocalDateTime.now();
        String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        List<OrderForm> orderForms = orderFormDAO.selectByEndOrderForm(format);

        for (OrderForm orderForm : orderForms ) {
           orderFormService.orderSuccess(orderForm);
        }
    }

}
